<template>
  <ve-card :title="managerItem.licenseNo || ' '" :sub-title="managerItem.vehicleStatusName" :type="getCardType(managerItem.vehicleStatus)">
    <ve-cell label="车牌颜色">{{ managerItem.licenseNoColorName }}</ve-cell>
    <ve-cell label="车型">{{ managerItem.modelName }}</ve-cell>
    <ve-cell label="车架号">{{ managerItem.vin }}</ve-cell>
    <ve-cell label="设备供应商">{{ managerItem.vehicleFirm }}</ve-cell>
    <ve-cell label="设备SN/ID">{{ managerItem.vehicleSn }}</ve-cell>
    <ve-operate-list :operates="operates" :record="managerItem" />
  </ve-card>
</template>
<script setup lang="ts">
  import { getCarGpsOne } from '@/api/asset/car-virtual'
  import { ref } from 'vue'

  const props = defineProps({
    managerItem: {
      type: Object,
      default: () => ({}),
    },
  })

  const getCardType = (record) => {
    // 设备状态颜色：0：未安装、1:在线、2:不在线、3:未知、9:安装失败
    switch (Number(record)) {
      case 0:
      case 3:
      case 9:
        return 'gray'
      case 1:
        return 'blue'
      case 2:
        return 'danger'
    }
  }
  // 只有设备在线与不在线时，才可以操作按钮
  const operates = [1, 2].includes(Number(props.managerItem.vehicleStatus))
    ? ref([
        {
          label: '开门并供电',
          permission: 'svmsapp:car-boxuse.openAndPower',
          method: () => {
            uni.$emit('openAndPowerFn', props.managerItem.id)
          },
        },
        {
          label: '锁门并断电',
          permission: 'svmsapp:car-boxuse.lockAndPowerOff',
          method: () => {
            uni.$emit('lockAndPowerOffFn', props.managerItem.id)
          },
        },
        {
          label: '鸣笛寻车',
          permission: 'svmsapp:car-boxuse.whistle',
          method: () => {
            uni.$emit('whistleFn', props.managerItem.id)
          },
        },
        {
          label: '开门',
          permission: 'svmsapp:car-boxuse.open',
          method: () => {
            uni.$emit('openFn', props.managerItem.id)
          },
        },
        {
          label: '锁门',
          permission: 'svmsapp:car-boxuse.lock',
          method: () => {
            uni.$emit('lockFn', props.managerItem.id)
          },
        },
        {
          label: '供电',
          permission: 'svmsapp:car-boxuse.powerSupply',
          method: () => {
            uni.$emit('powerSupplyFn', props.managerItem.id)
          },
        },
        {
          label: '断电',
          permission: 'svmsapp:car-boxuse.outage',
          method: () => {
            uni.$emit('outageFn', props.managerItem.id)
          },
        },
        {
          label: '位置',
          permission: 'svmsapp:car-boxuse.location',
          method: () => {
            let { licenseNo, vehicleSn } = props.managerItem
            getCarGpsOne({ licenseNo, vehicleSn }).then(({ result }) => {
              uni.navigateTo({
                url: `/pages/asset/car-boxuse/show-map?latitude=${result.latitudeGcj}&longitude=${result.longitudeGcj}&licenseNo=${licenseNo}`,
              })
            })
          },
        },
      ])
    : []
</script>
